package com.penghaisoft.microwms.materialhand.web.outwarehouse.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.penghaisoft.microwms.common.Constant;
import com.penghaisoft.microwms.common.controller.HandBaseController;
import com.penghaisoft.microwms.common.dto.HandResp;
import com.penghaisoft.microwms.common.dto.RawBackDto;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.materialhand.web.outwarehouse.service.IMaterialHandOutWhService;

/**
 * @program: micro-wms
 * @description: 退料接口
 * @author: zhangx
 * @create: 2018-05-17 15:21
 **/
@RestController
@RequestMapping("outwh/backmat")
public class BackMaterialController extends HandBaseController {

    @Autowired
    private IMaterialHandOutWhService materialHandOutWhService;
    /**
     * 扫描条码
     * @param rawBackDto
     * @return
     */
    @PostMapping("scan")
    public HandResp scanBarcode(@RequestBody RawBackDto rawBackDto){
        HandResp result = new HandResp();
        result.setCode(Constant.SUCCESS);
        if (rawBackDto.getBarcode()==null || rawBackDto.getBarcode().equals("")){
            result.setCode(Constant.FAIL);
            result.setMsg("请输入条码！");
            return result;
        }
        TransResult resp = materialHandOutWhService.backMatScanBar(rawBackDto);
        
        if (resp.getCode().equals(Constant.FAIL)){
        	result.setCode(Constant.FAIL);
            result.setMsg(resp.getMsg());
        }else {
            List list = new ArrayList<>();
            list.add(resp.getData());
            result.setList(list);
            result.setValue(resp.getMsg());
        }
        return result;
    }
}
